from utils.alipay import AliPay
from django.conf import settings



def alipay_link(order_id, title, price):
    ali_pay = AliPay(
        appid=settings.ALI_APPID,
        app_notify_url=settings.ALI_NOTIFY_URL,
        return_url=settings.ALI_RETURN_URL,
        app_private_key_path=settings.ALI_PRI_KEY_PATH,
        alipay_public_key_path=settings.ALI_PUB_KEY_PATH
    )
    query_params = ali_pay.direct_pay(
        subject=title,  # 商品简单描述
        out_trade_no=order_id,  # 商户订单号
        total_amount=price
    )
    pay_url = "{}?{}".format(settings.ALI_GATEWAY, query_params)
    return pay_url
